package com.our.controller;


import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.google.gson.Gson;
import com.mysql.fabric.xmlrpc.base.Array;
import com.our.biz.CalculateBiz;
import com.our.biz.ReportsBiz;
import com.our.model.UserPro;
import com.our.util.BusinessException;


@Controller
@RequestMapping("/data")
public class CalculateController {
	
	@Resource
	private CalculateBiz biz;
	@Resource
	private ReportsBiz rbiz;
	
	
	@RequestMapping("/calculate")
	public String calculate(String str,Map<String, Object> request){
		Date date = new Date();
		request.put("date", date);
		request.put("totaluser", biz.sumForUsersTotal(date));
		request.put("totalInvest",biz.sumForInvestTotal(date));
		request.put("totalInvestMoney",biz.sumInvestMoney(date));
		request.put("totalExpectedProfit", biz.sumExpectedProfit(date));
		return "/data/data";
	}
	@RequestMapping("/list")
	public String list(int typeId,Map<String, Object> request){
		try {
			request.put("list",rbiz.selectByTypeId(typeId));
		} catch (BusinessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "/data/list";
	}
	@RequestMapping("/topInvestOfUser")
	@ResponseBody
	public  Object topInvestOfUser(Map<String, Object> request){
		String str ="2017-08";
		List<UserPro> list = biz.topInvestOfUser(str);
		List<String> us = new ArrayList<>();
		List<Object> money = new ArrayList<>();
		for(UserPro up :list){
			us.add(up.getUser().getUsername());
			money.add(up.getInvestMoney());
		}
		Map<String,Object> map = new HashMap<>();
//		Gson gson = new Gson();
//		String json1 = gson.toJson(us);
//		String json2 = gson.toJson(money);
//		jsonlist.add(json1);
//		jsonlist.add(json2);
		map.put("json1", us);
		map.put("json2", money);
//		System.out.println("--------------------" + map.size());
//		String json3 = gson.toJson(map);
//		map.put("json3", json3);
//		System.out.println("--------------------" + json3);
		return map;
	}
	@RequestMapping("/topInvestOfUser1")
	public String topInvestOfUser1(Map<String, Object> request){
		String str ="2017-08";
		request.put("list", biz.topInvestOfUser(str));
		return "/data/top";
	}
	

}
